import 'package:aero_frisbee/app/state/app_cache_state.dart';
import 'package:aero_frisbee/app_route.dart';
import 'package:aero_frisbee/core/tools/af_log_manager.dart';
import 'package:aero_frisbee/gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

class AfProfileScreen extends StatelessWidget {
  const AfProfileScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      elevation: 0, // Optional: Set elevation to 0 to remove shadow
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius
            .zero, // Set border radius to zero for no rounded corners
      ),
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(0),
          border: Border.all(
            color: Colors.grey,
            width: 1,
          ),
        ),
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            SizedBox(
              height: MediaQuery.of(context).padding.top + 20,
            ),
            Consumer(
              builder: (context, ref, child) {
                return ProfileSettingItem(
                  icon:
                      Assets.images.mine.mineRightMenuCustomer.image(width: 28),
                  title: 'Customer Service',
                  onTap: () {
                    final curLogin = ref.read(curlUserInfoProvider);
                    if (curLogin != null) {
                      AFLogPvManger.stat(page: AFLogPages.customer);
                      context.pushNamed(RouteUri.messageDetai, queryParams: {
                        "userId": curLogin.userServiceAccountId ?? ''
                      });
                    }
                  },
                );
              },
            ),
            ProfileSettingItem(
              icon: Assets.images.mine.mineRightMenuBlocked.image(width: 28),
              title: 'Blocked list',
              onTap: () {
                context.pushNamed(RouteUri.blockList);
              },
            ),
            ProfileSettingItem(
              icon: Assets.images.mine.mineRightMenuAbout.image(width: 28),
              title: 'About',
              onTap: () {
                context.pushNamed(RouteUri.about);
              },
            ),
            ProfileSettingItem(
              icon: Assets.images.mine.mineRightMenuSetting.image(width: 28),
              title: 'Setting',
              onTap: () {
                context.pushNamed(RouteUri.setting);
              },
            ),

            // Add more ListTile widgets for other items
          ],
        ),
      ),
    );
  }
}

class ProfileSettingItem extends StatelessWidget {
  const ProfileSettingItem({
    Key? key,
    required this.icon,
    required this.title,
    this.onTap,
  }) : super(key: key);

  final Widget icon;
  final String title;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        Navigator.of(context).maybePop();
        onTap?.call();
      },
      child: Container(
        decoration: const BoxDecoration(
          color: Colors.white,
        ),
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const SizedBox(
              width: 8,
            ),
            Flexible(
              child: Row(
                children: [
                  icon,
                  const SizedBox(
                    width: 12,
                  ),
                  Flexible(
                    child: Text(
                      title,
                      style: const TextStyle(
                        color: Color(0xff141414),
                        fontWeight: FontWeight.normal,
                        fontSize: 14,
                      ),
                      textAlign: TextAlign.center,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                    ),
                  ),
                ],
              ),
            ),
            Assets.images.mine.mineRightMenuDetail.image(width: 16)
          ],
        ),
      ),
    );
  }
}
